package java_12_20;

public class Demo2 {
    public static void main(String[] args) {
        //在哪里调用得方法就返回的哪个线程
       Thread thread=Thread.currentThread();
        System.out.println(thread.getName());

//在run里面Thread.currentThread().getName()和this.getName作用相同
        Thread t2=new Thread(){
            public void run(){
                System.out.println(Thread.currentThread().getName());
                System.out.println(this.getName());
            }
        };
        t2.start();

        ////在Runnable里面没有name这个属性，所以想要获取名称需要用Thread.currentThread().getName()
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
                //System.out.println(this.getName());
            }
        });
        t3.start();
    }
}